﻿using System;
using System.IO;
using System.Text.RegularExpressions;
using JetBrains.Annotations;
using WikiDoc.Lines;

namespace WikiDoc
{
    /// <summary>
    /// 
    /// </summary>
    public class WikiReader 
    {
        /// <summary>
        /// Initializes a new instance of the IWikiReader class.
        /// </summary>
        /// <param name="reader">The reader.</param>
        public WikiReader(TextReader reader)
        {
            BaseReader = reader;
        }

        internal TextReader BaseReader;

        /// <summary>
        /// Reads the line and parse.
        /// </summary>
        /// <returns></returns>
        public string ReadLine()
        {
            string line = BaseReader.ReadLine();

            if (line == null)
            {
                _currentLine = WikiLine.EofLine;

                return null;
            }

            _currentLine = WikiLine.Parse(line);

            return line;
        }


        private WikiLine _currentLine;

        /// <summary>
        /// Gets or sets the current line info.
        /// </summary>
        /// <value>The current line info.</value>
        public WikiLine CurrentLine
        {
            get
            {
                if (_currentLine == null)
                {
                    ReadLine();
                }

                return _currentLine;
            }
        }

    }

}
